< Prev(J) / Next(K) > / View :

Filename: /text/sbasic/shared/03020202.xhp

(section: input) (bookmark: bm_id3154908)
Input statement

Input ステートメント

Input# Statement [Runtime]
Input# ステートメント [実行時](hd_id3154908.1)

Reads data from an open sequential file.
オープン済みの順編成ファイルからデータを読み取ります。(par_id3156424.2)

(/section: input)

Syntax:
構文:(hd_id3125863.3)

Input #FileNumber As Integer; var1[, var2[, var3[,...]]]
Input #FileNumber As Integer; var1[, var2[, var3[,...]]](par_id3150440.4)

Parameters:
パラメータ:(hd_id3146121.5)

FileNumber: Number of the file that contains the data that you want to read. The file must be opened with the Open statement using the key word INPUT.
FileNumber: 読み取るデータを含むファイルの番号。読み取るファイルは、Open ステートメントに INPUT キーワードを指定して、事前にオープンしておく必要があります。(par_id3145749.6)

var: A numeric or string variable that you assign the values read from the opened file to.
var: オープン済みのファイルから読み取った値を格納する、数値型ないし文字列型の変数。(par_id3150011.7)

The Input# statement reads numeric values or strings from an open file and assigns the data to one or more variables. A numeric variable is read up to the first carriage return (Asc=13), line feed (Asc=10), space, or comma. String variables are read to up to the first carriage return (Asc=13), line feed (Asc=10), or comma.
Input# ステートメントは、オープン済みのファイルから数値ないし文字列を読み取り、これらの値を 1 つまたは複数の変数に格納します。数値は、次に来るキャリッジリターン (ASC=13)、ラインフィード (ASC=10)、スペース、コンマまでのデータが、1 度に読み取られます。文字列は、次に来るコードがキャリッジリターン (ASC=13)、ラインフィード (ASC=10)、コンマまでのデータが、1 度に読み取られます。(par_id3159153.8)

Data and data types in the opened file must appear in the same order as the variables that are passed in the "var" parameter. If you assign non-numeric values to a numeric variable, "var" is assigned a value of "0".
オープン済みファイル中にあるデータおよびデータ型は、「var」に指定する変数の順序と一致している必要があります。数値以外のデータを数値変数に代入すると、「var」の変数には「0」値が格納されます。(par_id3146984.9)

Records that are separated by commas cannot be assigned to a string variable. Quotation marks (") in the file are disregarded as well. If you want to read these characters from the file, use the Line Input# statement to read pure text files (files containing only printable characters) line by line.
コンマで区切られているレコードを文字列値に割り当てることはできません。 同じようにファイル内の引用符 (") も無視されます。 ファイルからこのような文字を読み取る場合は Line Input# 文を使用し、テキストファイル (印刷可能な文字のみで構成されるファイル) を読み取ります。(par_id3156442.10)

If the end of the file is reached while reading a data element, an error occurs and the process is aborted.
データの読み取り中にファイル末尾に到達すると、エラーが発生してプロセスは終了させられます。(par_id3147349.11)

Example:
例:(hd_id3152578.12)

Sub ExampleWorkWithAFile
Sub ExampleWorkWithAFile(par_id3144765.13)

Dim iNumber As Integer
Dim iNumber As Integer(par_id3145799.14)

Dim sLine As String
Dim sLine As String(par_id3145252.15)

Dim aFile As String
Dim aFile As String(par_id3149410.16)

Dim sMsg as String
Dim sMsg as String(par_id3149959.39)

aFile = "c:\data.txt"
aFile = "c:\data.txt"(par_id3153417.17)

iNumber = Freefile
iNumber = Freefile(par_id3150752.19)

Open aFile For Output As #iNumber
Open aFile For Output As #iNumber(par_id3153707.20)

Print #iNumber, "This is a line of text"
Print #iNumber, "This is a line of text"(par_id3150321.21)

Print #iNumber, "This is another line of text"
Print #iNumber, "This is another line of text"(par_id3154756.22)

Close #iNumber
Close #iNumber(par_id3148408.23)

iNumber = Freefile
iNumber = Freefile(par_id3155937.27)

Open aFile For Input As iNumber
Open aFile For Input As iNumber(par_id3154702.28)

While not eof(iNumber)
While not eof(iNumber)(par_id3155959.29)

Line Input #iNumber, sLine
Line Input #iNumber, sLine(par_id3145232.30)

If sLine <>"" then
If sLine <>"" then(par_id3147345.31)

sMsg = sMsg & sLine & chr(13)
sMsg = sMsg & sLine & chr(13)(par_id3150298.32)

end if
end if(par_id3154021.34)

wend
Wend(par_id3154665.35)

Close #iNumber
Close #iNumber(par_id3155607.36)

Msgbox sMsg
Msgbox sMsg(par_id3153268.40)

End Sub
End Sub(par_id3152584.37)


< Prev / Next >